package com.lm.selenium.controller;

import com.lm.selenium.service.ProxyService;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/proxy")
public class ProxyController {

    private final ProxyService proxyService;

    public ProxyController(ProxyService proxyService) {
        this.proxyService = proxyService;
    }

    @GetMapping("/random")
    public String getProxy() {
        if (!proxyService.hasAvailableProxy()) {
            return "无可用代理，请刷新代理池";
        }
        return proxyService.getRandomProxy();
    }

    @PostMapping("/fail")
    public String markFail(@RequestParam String proxy) {
        proxyService.markFailed(proxy);
        return "已移除失效代理：" + proxy;
    }

    @PostMapping("/refresh")
    public String refresh() {
        proxyService.refreshPool();
        return "代理池刷新完成";
    }
}

